<?php
class lappersediaan_model extends CI_Model{
	private $KodeStok;
	private $NamaBarang;
	private $Namasupplier;
	private $Jmlmasuk;
	private $Jmlkeluar;
	private $StockAkhir;

	private $tglAkhir;
	private $tglAwal;
	
	function setKodeStok($KodeStok){
		$this->KodeStok = $KodeStok;
	}
	function getKodeStok(){
		return $this->KodeStok;
	}
	
	function setNamaBarang($NamaBarang){
		$this->NamaBarang = $NamaBarang;
	}
	function getNamaBarang(){
		return $this->NamaBarang;
	}
	
	function setNamasupplier($Namasupplier){
		$this->Namasupplier = $Namasupplier;
	}
	function getNamasupplier(){
		return $this->Namasupplier;
	}

	function setJmlmasuk($Jmlmasuk){
		$this->Jmlmasuk = $Jmlmasuk;
	}
	function getJmlmasuk(){
		return $this->Jmlmasuk;
	}
	
	function setJmlkeluar($Jmlkeluar){
		$this->Jmlkeluar = $Jmlkeluar;
	}
	function getJmlkeluar(){
		return $this->Jmlkeluar;
	}
	
	function setStockAkhir($StockAkhir){
		$this->StockAkhir = $StockAkhir;
	}
	function getStockAkhir(){
		return $this->StockAkhir;
	}
	
	function setActive($active_val){
		$this->Active = $active_val;
	}
	function getActive(){
		return $this->Active;
	}
	
	function setTanggalAwal($tglAwal){
		$this->tglAwal = $tglAwal;
	}
	function getTanggalAwal(){
		return $this->tglAwal;
	}
	
	function setTanggalAkhir($tglAkhir){
		$this->tglAkhir = $tglAkhir;
	}
	function getTanggalAkhir(){
		return $this->tglAkhir;
	}
	
	// Call the module constructor
	function __construct(){
		parent::__construct();
	}
	
	function getkodebrg(){
		$tanggal=date('Y-m-d', strtotime('now'));
		$this->db->select("detail_product.KodeDetailBarang,detail_product.Productname")->join('detail_product', 'detail_product.KodeDetailBarang=stock.KodeDetailBarang')
			->where(array('stock.Active'=>'1'));
        $query = $this->db->get('stock');
        return $query->result();
	}
	
	function getList(){
		$tanggal=date('Y-m-d', strtotime('now'));
		$this->db->select("stock.KodeStok,stock.CreatedOn,stock.KodeSupplier,supplier.Suppliername,stock.KodeDetailBarang,detail_product.Productname,stock.StockAkhir,stock.CreatedBy")
		->join('transaction_stock', 'transaction_stock.KodeStok=stock.KodeStok')
		->join('supplier', 'supplier.KodeSupplier=stock.KodeSupplier')
		->join('detail_product', 'detail_product.KodeDetailBarang=stock.KodeDetailBarang')
		/*->where(array('stock.CreatedBy' => $tanggal,'stock.Active'=>'1'));*/
		->where(array('stock.Active'=>'1'))->group_by('stock.KodeStok');
        $query = $this->db->get('stock');
        return $query->result();
	}
	
	function getListtanggal() {
        /*$this->db->select("stock.KodeStok,stock.CreatedOn,stock.KodeSupplier,supplier.Suppliername,stock.KodeDetailBarang,detail_product.Productname,stock.StockAkhir,stock.CreatedBy")
		->join('transaction_stock', 'transaction_stock.KodeStok=stock.KodeStok')
		->join('supplier', 'supplier.KodeSupplier=stock.KodeSupplier')
		->join('detail_product', 'detail_product.KodeDetailBarang=stock.KodeDetailBarang')
			->where ('stock.CreatedBy BETWEEN '.$this->getTanggalAwal().' AND '.$this->getTanggalAkhir().'');
        $query = $this->db->get('stock'); */
		
		$query = $this->db->query("select stock.KodeStok,stock.CreatedOn,stock.KodeSupplier,supplier.Suppliername,stock.KodeDetailBarang,detail_product.Productname,stock.StockAkhir,stock.CreatedBy from stock inner join transaction_stock on transaction_stock.KodeStok=stock.KodeStok
		inner join supplier on supplier.KodeSupplier=stock.KodeSupplier
		inner join detail_product on detail_product.KodeDetailBarang=stock.KodeDetailBarang
		where stock.Active = '1' AND stock.CreatedOn BETWEEN '".$this->getTanggalAwal()."' AND '".$this->getTanggalAkhir()."' GROUP BY stock.KodeStok"); 
		
        return $query->result();
    }
	
	function getkdbaranglike($kodebarang){
		$this->db->select("stock.KodeStok,stock.CreatedOn,stock.KodeSupplier,supplier.Suppliername,stock.KodeDetailBarang,detail_product.Productname,stock.StockAkhir,stock.CreatedBy")
		->join('transaction_stock', 'transaction_stock.KodeStok=stock.KodeStok')
		->join('supplier', 'supplier.KodeSupplier=stock.KodeSupplier')
		->join('detail_product', 'detail_product.KodeDetailBarang=stock.KodeDetailBarang')
		->where(array('stock.Active'=>'1'))->like(array('stock.KodeDetailBarang' => $kodebarang))->group_by('stock.KodeStok');
		$query = $this->db->get('stock');
		return $query->result();
	}
	
}